package com.arrogames.tmx {
	import flash.geom.Point;

	public class CoordinateUtil {
		
		public static function isometricToScreen(gridX:Number, gridY:Number, tileWidth:Number, tileHeight:Number):Point {
			var screenX:Number = (gridX - gridY) * (tileWidth/2);
			var screenY:Number = (gridX + gridY) * (tileHeight/2);
			return new Point(screenX, screenY);
		}
		
		public static function screenToIsometric(screenX:Number, screenY:Number, tileWidth:Number, tileHeight:Number):Point {
			var gridX:Number = (screenX / tileWidth) + (screenY / tileHeight);
			var gridY:Number = (screenY / tileHeight) - (screenX / tileWidth);
			return new Point(gridX, gridY);
		}
		
		public static function isoScreenToIso(isoScreenX:Number, isoScreenY:Number, tileWidth:Number, tileHeight:Number):Point {
			var gridX:Number = Math.floor(isoScreenX/(tileWidth/2));
			var gridY:Number = Math.floor(isoScreenY/tileHeight);
			return new Point(gridX, gridY);
		}
		
		public static function orthogonalToScreen(x:Number, y:Number, tileWidth:Number, tileHeight:Number):Point {
			var posX:Number = x * tileWidth;
			var posY:Number = y * tileHeight;
			return new Point(posX, posY);
		}
		
		public static function screenToOrthogonal(x:Number, y:Number, tileWidth:Number, tileHeight:Number):Point {
			var posX:Number = x / tileWidth;
			var posY:Number = y / tileHeight;
			return new Point(posX, posY);
		}
	}
}